package ch.unisi.inf.pfii.teamwhite.risk.graphic.gameFrame;

/**
 * 
 * @author Matteo Bellan: bellanm@lu.unisi.ch
 * @author Andrea Michelotti: micheloa@lu.unisi.ch
 * @author Ranganathan Ramasubramanian: ramasubr@lu.unisi.ch
 *
 */

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import ch.unisi.inf.pfii.teamwhite.risk.core.Game;

public class PlayerInfoPanel extends JPanel{

	private Image image;
		
	public PlayerInfoPanel(final Game game){
		setLayout(new GridLayout());
		
		try
	    {
	      image = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("HUD/nord.png"), "nord.png"));
	    }
	    catch (Exception e) { 
	    	System.out.println("failed");
	    }
	    
		if (!(game.getCurrentPlayer() == null)) {
			add(makeMoney(game));
			add(makeName(game));
			add(makeType(game));
		}
		setVisible(true);
	}
	
//	This method paint the background image on this panel
	@Override
    protected void paintComponent(Graphics g) {
	    super.paintComponent(g); 
	    if (image != null) {
	    	g.drawImage(image, 0, 0, this.getWidth(), this.getHeight() + 20,this);
	    }
	}
	
//	This methods creates labels containing the info of the player to show on the frame
	private Component makeMoney(final Game game){
		final JLabel money = new JLabel("Money: " + game.getCurrentPlayer().getMoney(), SwingConstants.CENTER);
		money.setForeground(Color.WHITE);
		return money;
	}
	
	private Component makeName(final Game game){
		final JLabel player = new JLabel("Player: " + game.getCurrentPlayer().getName(), SwingConstants.CENTER);
		player.setForeground(Color.WHITE);
		return player;
	}
	
	private Component makeType(final Game game){
		final JLabel type = new JLabel("Type: " + game.getCurrentPlayer().getType(), SwingConstants.CENTER);
		type.setForeground(Color.WHITE);
		return type;
	}
}
